package org.visionlibrary.image.model;

import javax.media.jai.TiledImage;

import org.visionlibrary.image.acquisition.ImageFactory;


public abstract class PixelFilter extends AbstractFilter {
	abstract protected int getNewPixelVal(int value);

	@Override
	public TiledImage applyFilter(TiledImage src, TiledImage dest) {
		if(null == src)
			throw new NullPointerException("Source image is null.");
		
		if (null == dest)
			dest = (new ImageFactory()).createCompatibleImage(src);

		
		int channels = src.getNumBands();
		int width = src.getWidth();
		int height = src.getHeight();
		
		for (int ch = 0; ch < channels; ch++)
			for (int x = 0; x < width; x++)
				for (int y = 0; y < height; y++) {
					int pixel = getNewPixelVal(src.getSample(x, y, ch));
					dest.setSample(x, y, ch, pixel);
				}

		
		return dest;
	}

}
